using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.Practices.RepositoryFactory.CodeGeneration.ObjectModel;
using Microsoft.Practices.RepositoryFactory.CodeGeneration.ObjectModel.Mappings;
using Microsoft.Practices.RepositoryFactory.SchemaDiscovery.ObjectModel.Base;
using NUnit.Framework;

namespace Microsoft.Practices.RepositoryFactory.Tests.CodeGeneration.ObjectModel
{
    public abstract class IdentityHelperFixture
    {
        [Test]
        public void GetIdentityConstructor_WithNullIdentity()
        {
            Assert.IsEmpty(IdentityHelper.GetIdentityConstructor(null, false, false));
            Assert.IsEmpty(IdentityHelper.GetIdentityConstructor(null, true, false));
            Assert.IsEmpty(IdentityHelper.GetIdentityConstructor(null, false, true));
            Assert.IsEmpty(IdentityHelper.GetIdentityConstructor(null, true, true));
        }

        [Test]
        public void GetIdentityConstructor_WithSingleParameter()
        {
            Identity identity = new Identity();
            identity.Name = "Identity";
            identity.ParameterMappings = new List<PropertyParameterMapping>();

            Parameter parameter = new Parameter();
            parameter.Direction = ParameterDirection.Input;
            parameter.DBName = "parameterName";
            parameter.DbDataType = new DbDataType();
            parameter.DbDataType.Type = typeof (Int32);

            identity.ParameterMappings.Add(new PropertyParameterMapping("NameId", parameter));

            string response = IdentityHelper.GetIdentityConstructor(identity, false);
            Assert.AreEqual("System.Int32 nameId", response);
            response = IdentityHelper.GetIdentityConstructor(identity, true);
            Assert.AreEqual("nameId", response);
        }

        [Test]
        public void GetIdentityConstructor_WithMultipleParameters()
        {
            Identity identity = new Identity();
            identity.Name = "Identity";
            identity.ParameterMappings = new List<PropertyParameterMapping>();

            Parameter parameter = new Parameter();
            parameter.Direction = ParameterDirection.Input;
            parameter.DBName = "parameterNameId";
            parameter.DbDataType = new DbDataType();
            parameter.DbDataType.Type = typeof(Int32);
            identity.ParameterMappings.Add(new PropertyParameterMapping("NameId", parameter));

            parameter = new Parameter();
            parameter.Direction = ParameterDirection.Input;
            parameter.DBName = "parameterName";
            parameter.DbDataType = new DbDataType();
            parameter.DbDataType.Type = typeof(string);
            identity.ParameterMappings.Add(new PropertyParameterMapping("Name", parameter));

            string response = IdentityHelper.GetIdentityConstructor(identity, false);
            Assert.AreEqual("System.Int32 nameId, System.String name", response);
            response = IdentityHelper.GetIdentityConstructor(identity, true);
            Assert.AreEqual("nameId, name", response);
        }
    }
}
